<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
		<!-- Google Chrome Frame也可以让IE用上Chrome的引擎: -->
		<meta name="renderer" content="webkit">
		<!--国产浏览器高速模式-->
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>电力通信管理系统</title>

		<!-- 公共样式 开始 -->
		<link rel="shortcut icon" href="images/favicon.ico"/>
		<link rel="bookmark" href="images/favicon.ico"/>
		<link rel="stylesheet" type="text/css" href="css/base.css">
		<link rel="stylesheet" type="text/css" href="css/iconfont.css">
		<script type="text/javascript" src="framework/jquery-1.11.3.min.js" ></script>
		<link rel="stylesheet" type="text/css" href="layui/css/layui.css">
	    <!--[if lt IE 9]>
	      	<script src="framework/html5shiv.min.js"></script>
	      	<script src="framework/respond.min.js"></script>
	    <![endif]-->
		<link rel="stylesheet" type="text/css" href="css/jquery.mCustomScrollbar.css">
		<link rel="stylesheet" type="text/css" href="css/frameStyle.css">



	</head>

	<body>
		<!-- 左侧菜单 - 开始 -->
		<div class="frameMenu">
		    <div class="logo">
		        <img src="images/logo.png"/>
		        <div class="logoText">
		            <h1>电力通信管理系统</h1>
		            <p>DIANLITONGXIN</p>
		        </div>
		    </div>
		    <div class="menu" id="menu">
		        <ul id="menus">

		        </ul>
				<script>
					function initMenu() {
						var roles=JSON.parse(window.sessionStorage.getItem("roles"));
						var menus=$("#menus")
						var role=window.sessionStorage.getItem("role")
						if(role*1===2){
							$("#mainIframe").attr("src",roles[0].roleListItemVos[0].url)
						}else{
							$("#mainIframe").attr("src",roles[0].roleListItemVos[1].url)
						}

						roles.forEach(function (item,index) {
							console.log(item)
							var li=$("<li></li>")
							var a=$("<a class=\"menuFA\" href=\"javascript:void(0)\"  ></a>")
							var i=$("<i class=\"iconfont icon-"+item.icon+" left\"></i>")
							a.append(i)
							a.append(item.parentName)
							if(item.roleListItemVos.length>0){
								var i2=$("<i class=\"iconfont icon-dajiantouyou right\"></i>")
								a.append(i2)
								li.append(a)
								var dl=$("<dl></dl>")
								item.roleListItemVos.forEach(function (item1,index) {
									var dt=$("<dt></dt>")
									var a=$("<a href=\"javascript:void(0)\" onclick=\"menuCAClick('"+item1.url+"',this)\">"+item1.name+"</a>")
									dt.append(a)
									dl.append(dt)
								})
								dl.css('display',"none")
								li.append(dl)
							}
							menus.append(li)
						})
					}
				</script>
		    </div>
		</div>
		<!-- 左侧菜单 - 结束 -->

		<div class="main">
			<!-- 头部栏 - 开始 -->
			<div class="frameTop">
				<img class="jt" src="images/top_jt.png"/>
				<div class="topMenu">
					<ul>
						<li><a href="javascript:void(0)" id="userName" onclick="menuCAClick('tgls/modify_password.html',this)"><i class="iconfont icon-yonghu1"></i>管理员</a></li>
						<li><a href="javascript:void(0)" onclick="menuCAClick('tgls/modify_password.html',this)"><i class="iconfont icon-xiugaimima"></i>修改密码</a></li>
						<li id="loginOut"><a href="#"><i class="iconfont icon-084tuichu"></i>注销</a></li>
					</ul>
				</div>
			</div>
			<!-- 头部栏 - 结束 -->

			<!-- 核心区域 - 开始 -->
			<div class="frameMain">
				<div class="title" id="frameMainTitle">
					<span><i class="iconfont icon-xianshiqi"></i>首页</span>
				</div>
				<div class="con">
					<iframe id="mainIframe" src="tgls/users/users_list.html" scrolling="no"></iframe>
				</div>
			</div>
			<!-- 核心区域 - 结束 -->
		</div>
	</body>
<script>
    $(document).ready(function(){
    	var i=0
        var user=JSON.parse(window.sessionStorage.getItem("user"));
        if(user==null){
            window.location.assign("login.html")
        }
        $("#userName").text(user.managername);
        user=user.managerid;
        initMenu()
		loop()
		i=setInterval(function () {
			loop(user,i)
			console.log(111)
		},1000)
    });
    function loop(user,i){
		$.ajax({
			xhrFields: {
				withCredentials: true
			},
			crossDomain: true,
			type: "get",
			dataType: "json",
			url: "http://localhost:8888/user/checkLogin/"+user,
			success: function (data) {
				if (data.code == 0) {

				} else {
					layer.msg(data.msg)
					window.sessionStorage.removeItem("user");
					window.sessionStorage.removeItem("token");
					clearInterval(i)
					setTimeout(function () {
						window.location.assign("login.html")
					},1000)

				}
			},error:function () {
				layer.msg("登录信息已失效，请重新登录")
				window.sessionStorage.removeItem("user");
				window.sessionStorage.removeItem("token");
				clearInterval(i)
				setTimeout(function () {
					window.location.assign("login.html")
				},1000)
			}
		})
	}
    $("#loginOut").click(function () {
        var user=JSON.parse(window.sessionStorage.getItem("user"));
        $.ajax({
            // headers:{
            //     "access_token":token
            // },
			xhrFields: {
				withCredentials: true
			},
			crossDomain: true,
            type: "get",
            dataType: "json",
            url: "http://localhost:8888/user/loginOut/"+user.managerid,
            success: function (data) {
                if (data.code == 0) {
                	layer.msg("注销成功")
					window.sessionStorage.removeItem("user");
					window.sessionStorage.removeItem("token");
                    setTimeout(function () {
						window.location.assign("login.html")
					},1000)
                } else {
                    layer.msg(data.msg)
                }
            }
        })
    });
</script>
	<script type="text/javascript" src="layui/layui.js"></script>
	<!-- 滚动条插件 -->
	<script src="framework/jquery-ui-1.10.4.min.js"></script>
	<script src="framework/jquery.mousewheel.min.js"></script>
	<script src="framework/jquery.mCustomScrollbar.min.js"></script>
	<script src="framework/cframe.js"></script><!-- 仅供所有子页面使用 -->
	<!-- 公共样式 结束 -->

	<script type="text/javascript" src="framework/frame.js" ></script>
</html>
